<%-- 
    Document   : tableAddEdit
    Created on : 24/02/2013
    Author     : Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add/Edit Table</title>
        <script type="text/javascript">
            var isEdit = ${isEdit};
            var selectControl;
            $(document).ready(function(){
                uic.simpleform({
                    id: 'simpleform',
                    showTitle: false,
                    target: $('div.add_edit')
                }).add(selectControl = uic.control.dropdown({
                    id: 'name',
                    title: 'Table',
                    disabled: isEdit,
                    rules: {
                        required: true,
                        messages: {
                            required: "Please select table"
                        }
                    }
                })).add(uic.control.input({
                    id: 'desc',
                    title: 'Description',
                    value: '${obj.description}'
                })).addButton(uic.element.button({
                    onclick: function(){
                        model.submit({
                            id: '${obj.id}',
                            name: $('#name').val(),
                            desc: $('#desc').val()
                        }, isEdit);
                    },
                    id: 'submit',
                    title: 'Ok',
                    primary: true
                })).addButton(dialogManager.getCloseButton()).initValidation();
                
                getTablesList();
            });
            
            function getTablesList(){
                $.ajax({
                    url: isEdit ? 'list' : 'unique',
                    type: "POST",
                    async: false,
                    success: function(list) {
                        selectControl.setUnpreparedList({
                            list: list,
                            selectedValue: '${obj.name}'.toLowerCase(),
                            needEmptyOption: !isEdit
                        });
                    }
                });
            }
        </script>
    </head>
    <body>
        <div class="add_edit"></div>
    </body>
</html>
